﻿using System;
using System.Data;
using System.Collections.Generic;

namespace EnterpriseFund.BLL
{
    /// <summary>
    /// 业务逻辑类Entity 的摘要说明。
    /// </summary>
    public class Entity
    {
        private readonly DAL.Entity dal = new DAL.Entity();
        public Entity()
        { }
        #region  成员方法
        /// <summary>
        /// 是否存在该记录
        /// </summary>
        public bool Exists(string FEntityNo)
        {

            return dal.Exists(FEntityNo);
        }

        /// <summary>
        /// 增加一条数据
        /// </summary>
        public void Add(Model.Entity model)
        {
            dal.Add(model);

        }

        /// <summary>
        /// 更新一条数据
        /// </summary>
        public void Update(Model.Entity model)
        {
            dal.Update(model);
        }

        /// <summary>
        /// 删除一条数据
        /// </summary>
        public void Delete(string FEntityNo)
        {

            dal.Delete(FEntityNo);
        }

        /// <summary>
        /// 得到一个对象实体
        /// </summary>
        public Model.Entity GetModel(string FEntityNo)
        {




            return dal.GetModel(FEntityNo);
        }

       

        /// <summary>
        /// 获得数据列表
        /// </summary>
        public DataSet GetList(string strWhere)
        {
            return dal.GetList(strWhere);
        }
        /// <summary>
        /// 获得前几行数据
        /// </summary>
        public DataSet GetList(int Top, string strWhere, string filedOrder)
        {
            return dal.GetList(Top, strWhere, filedOrder);
        }
        /// <summary>
        /// 获得数据列表
        /// </summary>
        public List<Model.Entity> GetModelList(string strWhere)
        {
            DataSet ds = dal.GetList(strWhere);
            return DataTableToList(ds.Tables[0]);
        }
        /// <summary>
        /// 获得数据列表
        /// </summary>
        public List<Model.Entity> DataTableToList(DataTable dt)
        {
            List<Model.Entity> modelList = new List<Model.Entity>();
            int rowsCount = dt.Rows.Count;
            if (rowsCount > 0)
            {
                Model.Entity model;
                for (int n = 0; n < rowsCount; n++)
                {
                    model = new Model.Entity();
                    model.FEntityNo = dt.Rows[n]["FEntityNo"].ToString();
                    model.FEntityName = dt.Rows[n]["FEntityName"].ToString();
                    model.FLeader = dt.Rows[n]["FLeader"].ToString();
                    model.FShortName = dt.Rows[n]["FShortName"].ToString();
                    if (dt.Rows[n]["FAccessDate"].ToString() != "")
                    {
                        model.FAccessDate = DateTime.Parse(dt.Rows[n]["FAccessDate"].ToString());
                    }
                    model.FLastLoginIPAddr = dt.Rows[n]["FLastLoginIPAddr"].ToString();
                    model.FLogID = dt.Rows[n]["FLogID"].ToString();
                    if (dt.Rows[n]["fuseTimes"].ToString() != "")
                    {
                        model.fuseTimes = int.Parse(dt.Rows[n]["fuseTimes"].ToString());
                    }
                    model.FPublishRoot = dt.Rows[n]["FPublishRoot"].ToString();
                    if (dt.Rows[n]["FWaterMarkContent"].ToString() != "")
                    {
                        model.FWaterMarkContent = (byte[])dt.Rows[n]["FWaterMarkContent"];
                    }
                    model.FWaterMarkSvrFileName = dt.Rows[n]["FWaterMarkSvrFileName"].ToString();
                    model.FWaterMarkExt = dt.Rows[n]["FWaterMarkExt"].ToString();
                    model.FWaterMarkOldFileName = dt.Rows[n]["FWaterMarkOldFileName"].ToString();
                    model.FWebBeiAnNo = dt.Rows[n]["FWebBeiAnNo"].ToString();
                    model.FCopyRight = dt.Rows[n]["FCopyRight"].ToString();
                    model.FTxtWaterMark = dt.Rows[n]["FTxtWaterMark"].ToString();
                    model.FSmtpHost = dt.Rows[n]["FSmtpHost"].ToString();
                    model.FSmtpAccount = dt.Rows[n]["FSmtpAccount"].ToString();
                    model.FSmtpPassword = dt.Rows[n]["FSmtpPassword"].ToString();
                    model.FWaterMarkCls = dt.Rows[n]["FWaterMarkCls"].ToString();
                    if (dt.Rows[n]["FSmtpPort"].ToString() != "")
                    {
                        model.FSmtpPort = int.Parse(dt.Rows[n]["FSmtpPort"].ToString());
                    }
                    if (dt.Rows[n]["FIsSsl"].ToString() != "")
                    {
                        model.FIsSsl = decimal.Parse(dt.Rows[n]["FIsSsl"].ToString());
                    }
                    if (dt.Rows[n]["FFlowLockTime"].ToString() != "")
                    {
                        model.FFlowLockTime = int.Parse(dt.Rows[n]["FFlowLockTime"].ToString());
                    }
                    model.FIsIPControl = dt.Rows[n]["FIsIPControl"].ToString();
                    model.FNtkoCaption = dt.Rows[n]["FNTKOCaption"].ToString();
                    model.FNtkoKey = dt.Rows[n]["FNTKOKey"].ToString();
                    model.FSysTitle = dt.Rows[n]["FSysTitle"].ToString();
                    model.FSysCopyRight = dt.Rows[n]["FSysCopyRight"].ToString();
                    modelList.Add(model);
                }
            }
            return modelList;
        }

        /// <summary>
        /// 获得数据列表
        /// </summary>
        public DataSet GetAllList()
        {
            return GetList("");
        }

        /// <summary>
        /// 获得数据列表
        /// </summary>
        //public DataSet GetList(int PageSize,int PageIndex,string strWhere)
        //{
        //return dal.GetList(PageSize,PageIndex,strWhere);
        //}


        #endregion  成员方法


        #region 自己增加的方法

        public void UpdateByEntityNo(Model.Entity model)
        {
            dal.UpdateByEntityNo(model);
        }
        /// <summary>
        /// 更新部分数据
        /// </summary>
        public void UpdateSect(Model.Entity model)
        {
            dal.UpdateSect(model);
        }

        public void UpdateIpContral(string temp, string EntityNo)
        {
            dal.UpdateIpContral(temp, EntityNo);
        }


        /// <summary>
        /// 获取值班人员字符串组合
        /// </summary>
        /// <param name="_strEntityNO"></param>
        /// <param name="_strDay"></param>
        /// <returns></returns>
        public string getWatchScheduleName(string _strEntityNO, string _strDay)
        {
            return dal.getWatchScheduleName(_strEntityNO, _strDay);
        }

        #endregion

    }
}

